<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>促销管理</title>
<load href="__PUBLIC__/css/bootstrap.min.css" />
<import type='css' file="css.daterangepicker-bs3" />
<import type='css' file="css.main" />
<load href="__PUBLIC__/js/jquery-1.9.1.min.js" />
<load href="__PUBLIC__/js/jquery-ui.min.js" />
<import type='js' file="js.main" />
<import type='js' file="js.moment" />
<import type='js' file="js.daterangepicker" />
<link rel="stylesheet" type="text/css" href="/assets/css/batch_at.css" />
</head>

<body>
<!-- 如果没有加促销系统 -->
<if condition="$code_val eq 'no'">
	<div class="info_mask">
		<div class="bounced_info">
			<div class="bounced_img"><img src="/assets/img/icon_warning.png"></div>
			<div class="bounced_txt">
				<h3>操作提示</h3>
				<p>促销系统请先添加 <b>奖品规则</b></p>
				<span class="bounced_btn">
					<a href="{:U('Award/index')}" class="bounced_btn_ok">确认</a>
					<a class="bounced_btn_cancel">取消</a>
				</span>
			</div>
		</div>
	</div>
</if>
<script type="text/javascript">
	$(function(){
		$(".bounced_btn_cancel").click(function(){
			$(".info_mask").hide();
		})
		$('#pro_starttime').daterangepicker({ singleDatePicker: true }, function(start, end, label) {
			console.log(start.toISOString(), end.toISOString(), label);
		});
		$('#pro_endtime').daterangepicker({ singleDatePicker: true }, function(start, end, label) {
			console.log(start.toISOString(), end.toISOString(), label);
		});

		$("#setqrcode").click(function(){
			var rulesid  = $("select[name='rules']").val();
			var domainid = {$domainid};
			var rootid 	 = {$rootid};
			var m_num 	 = $("input[name='m_num']").val();
			var pici 	 = {$batch_result_count};
			if(m_num < 1){
				alert("生产数量不能为空！");
				return false;
			}
			$("#qrcodelist").show();
			$("#qrcodelist b").html("正在批量更新数据，请耐心等待...");
			var strurl = "/Admin/Batch/getqrcodelist";
			var teldata = {"domainid":domainid,"rootid":rootid,"make":1,"m_num":m_num,"rulesid":rulesid,"pici":pici,random:Math.random()};
			$.ajax({
				url:strurl,
				data:teldata,
				type:"POST",
				dataType:"html",
				success:function (data){
					//alert(data);
					//return false;
					if(data==1){
						allotaward(rootid, rulesid, pici);
						//$("#qrcodemakeok").show();
					}else if(data==-2){
						alert('选择规则出错');
						$("#qrcodelist").hide();
						return false;
					}else{
						alert('生产出错，停止生产，请重新来过');
						location.reload();
					}
				},
			});
		})
		$("#qrcodemakeok b").click(function(){
			location.reload();
		})

		//分配奖品
		function allotaward(rootid, rulesid, pici){
			var strurl = "/Admin/Batch/allotaward";
			var teldata = {"rootid":rootid,"rulesid":rulesid,"pici":pici,random:Math.random()};
			$.ajax({
				url:strurl,
				data:teldata,
				type:"POST",
				dataType:"html",
				success:function (data){
					//alert(data);
					//return false;
					if(data==1){
						$("#qrcodelist b").html("正在分配奖品，请耐心等待...");
						setTimeout("$('#qrcodemakeok').show()",5000);
					}
				},
			});
		}

	})
</script>

<if condition="$batch_result_count neq 0">
	<style type="text/css">
	.clpici{float: left; width: 6%; background-color: #00A388; height: 100%; position: fixed; padding-top: 85px; overflow: hidden;}
	.clpici a{display: block; width: 80%; clear: both; font-size: 14px; height: 30px; line-height: 30px; float: right; border-radius: 3px 0px 0px 3px; margin-top: 10px; background-color: #00A388; padding: 0px 6px; color: #fff; text-decoration: none;}
	.clpici a.hover{background-color: #fff; color: #606060;}
	.clpici a:hover{color: #606060;}
	.main-frame{float: right; width: 94%;}
	.position{margin-bottom:0px;}
	.selectform	.tle{margin-bottom:0px;}
	</style>
	<div class="clpici">
		<volist name='batch_result' id='v' key='k'>
		<a href="{:U('index', array('domainid' => $domainid, 'rootid' => $rootid, 'batchnumber' => $v['batchnumber']))}" <if condition="($pi_ci neq '') and ($v['batchnumber'] eq $pi_ci)">class='hover'<elseif condition="($pi_ci eq '') and ($v['batchnumber'] eq $batch_result_count)"/>class='hover'</if>>第 {$v['batchnumber']} 批</a>
		</volist>
	</div>
</if>
<style type="text/css">.lookreuslt{background-color: #00aced; height: 30px; line-height: 30px; color: #fff; border: none; padding: 0px 10px; border-radius: 3px; font-size: 14px;}</style>
<div class="main-frame">
	<div class="position">华人码 > 促销管理</div>
	
	<div class="selectform">
		<if condition="$Think.session.userinfo.type eq 1">
		<div class="export_sc">
			<!-- <label class="tle">批次：</label>
			<select name="batchnumber" class="select_rules" style="border: solid 1px #ccc; background-color: #fff; color:#333">
				<option value="1">1</option>
				<option value="2">2</option>
			</select> -->
			<select name="rules" class="select_rules">
				<volist name="marules" id="v">
					<option <if condition="$rulesid['isrules'] eq $v['id']">selected="selected"</if> value="{$v['id']}">{$v['typename']}</option>
				</volist>
			</select>		
			<input type="hidden" name="pici" value="{$pici}" />	
			<input type="hidden" name="rootid" value="{$rootid}" />
			<label class="fl tle">生产数量：</label>
			<input class="n_txt" name="m_num" style="color: #000;" placeholder="如：100" />
			<input id="setqrcode" class="n_txt" type="button" value="开始生产" />
		</div>
		</if>

		<div class="export">
			<if condition="$Think.session.userinfo.type eq 1">
				<notempty name="rulesarray">
					<volist name="rulesarray" id="r">
						<a href="{:U('exportdata',array('rootid'=>$rootid,'awardid'=>$r['id'],'batchnumber'=>$pi_ci))}" class="exportdata">导出{$r['awardname']}链接</a>
					</volist>
					<a href="{:U('exportdata',array('rootid'=>$rootid,'awardid'=>1,'batchnumber'=>$pi_ci))}" class="exportdata">导出剩余链接</a>
					<a href="{:U('batchqrcodes',array('rootid'=>$rootid,'batchnumber'=>$pi_ci))}" class="exportdata">导出二维码</a>
					<a class="exportdata resdel" refurl="{:U('ma_delete',array('rootid'=>$rootid,'batchnumber'=>$pi_ci))}" style="background-color:#f39c12; cursor:pointer; color:#fff"><if condition="($pi_ci neq '') and ($pi_ci gt 0)">删除第 {$pi_ci} 批码<else/>删除所有码</if></a>
				</notempty>
		    </if>
			
			<select class="lookreuslt">
				<option value='-1' selected>查看奖品结果</option>
				<volist name="rulesarray_awardkind" id='v'>
					<if condition="$v['awardkind'] neq 1">
					<option value='{$v['awardkind']}' url='{:U('Record/index',array('type'=>$v['awardkind'],'rootid'=>$rootid,'batchnumber'=>$pi_ci))}'>
						<switch name="v['awardkind']">
							<case value="2">实物奖品</case>
							<case value="3">现金红包</case>
							<case value="4">手机流量</case>
							<case value="5">手机话费</case>
						</switch>
					</option>
					</if>
				</volist>
			</select>
			<!--<a randcode="000000" vrootid="{$rootid}" awartype="" class="exportdata lookover" style="cursor: pointer; background-color: #0068aa; float: right; margin-right:0px;">查看所有中奖者信息</a>-->
		</div>

	</div>

	<div id="qrcodelist"><img src="/indexpublic/images/loading.gif" /><b></b></div>
	<div id="qrcodemakeok">生产完毕</em><b>X</b></div>

	<style type="text/css">
		.prizeinfo{clear: both; background-color: #eee; overflow: hidden; width: 100%; line-height: 26px; font-size: 14px; color: #fff;}
		.prizeinfo li{padding: 0px 3px; margin: 0px 3px; float:left;}
		.countstyle{float: left; width: 50%; text-align: left; background-color: #f39c12; padding:5px 0px;}
		.lqcountstyle{float: right; width: 50%; text-align: right; background-color: #00a65a; padding:5px 0px;}
		.page{margin-top:12px;}
		.select_rules{background-color:#fff; color:#606060;}
		.page{height: 84px;}
		.numinfos{position: fixed; bottom: 12px; width: 100%; text-align: center;}
	</style>
	<div class="prizeinfo">
		<!--奖品信息-->
		<div class="countstyle">
			<ul>
				<li>目标奖品：</li>
				<volist name="rulesarray" id="r">
					<li>{$r['awardname']}：{:W('Menutype/awardtype',array('rootid'=>$rootid,'matypeid'=>$r['id'],'r'=>$r['awardkind']))}</li>
				</volist>
			</ul>
		</div>
		<!--奖品领取信息-->
		<div class="lqcountstyle">
			<ul>
				<li>已领取数量：</li>
				<volist name="rulesarray" id="r">
					<li>{$r['awardname']}：{:W('Menutype/awardtype',array('rootid'=>$rootid,'matypeid'=>$r['id'],'r'=>$r['awardkind'],'lingqu'=>1))}</li>
				</volist>
			</ul>
		</div>
	</div>
	<style type="text/css">.th-bg th{color:#606060; font-weight:bold;}</style>
	<div class="table-list" style="border:none; margin-bottom:83px;">
	 <table width="100%" border="1" cellspacing="0" cellpadding="0" class="indextable">
		    <tr class="th-bg" style="background-color: #e7e7e7;">
		      <th width="6%">ID</th>
		      <th width="25%">码标题</th>
		      <!--<th width="12%">华人码</th>-->
			  <th width="12%">code序列号</th>
		      <th width="10%">中奖时间</th>
			  <th width="20%">奖品</th>
			  <th width="8%">奖品状态</th>
		      <th width="8%" style="text-align:center;">操作</th>
	        </tr>
	        <volist name='randlist' id='v' empty="$empty">
		    <tr class="tr-line" <if condition="$v['ma_hb_cishu'] eq 1">style="background-color: #fff; color: #fff;"</if>>
		      <td>{$v.id}</td>
		      <td style="text-align:left; padding-left:6px;">{:W('Menutype/typename',array($v['ma_rootid']))}</td>
		      <!--<td>{:W('Menutype/checkimg',array('imgpath'=>$v['ma_randcodeimgurl']))}</td>-->
		      <td>{$v.ma_randnumber}</td>
			  <td style="font-size:12px;"><if condition="$v['zjtime'] neq ''">{$v['zjtime']}<else/>-</if></td>
			  <td>{:W('Menutype/matype',array('matype'=>$v['ma_type']))}</td>
			  <td><if condition="$v['ma_hb_cishu'] eq 1"><span style="color:green;">已获取</span><else/>-</if></td>
		      <td class="operation" style="text-align:center;">
				  <!--<if condition="$v['ma_type'] eq 1">-->
					  <!--<a class="blue" href="{:U('setaward',array('id'=>$v['id'],'matype'=>2))}">设定实物</a>-->
				  <!--<elseif condition="$v['ma_type'] eq 2" />-->
					  <!--<a class="green" href="{:U('setaward',array('id'=>$v['id'],'matype'=>1))}">设定红包</a>-->
				  <!--</if>-->
				  <if condition="$v['ma_hb_cishu'] eq 1">
					  <!--<a style="cursor: pointer;" randcode="{$v['ma_randnumber']}" vrootid="" awartype="{:W('Menutype/matype',array('matype'=>$v['ma_type'],'afield'=>'awardkind'))}" class="lookover blue">查看</a>-->
				  	-
				  <else />
					  <if condition="$Think.session.userinfo.type eq 1">
				  	  <!-- <a style="cursor: pointer;" class="resdel red" refurl="{:U('madelete',array('id'=>$v['id'],'rootid'=>$rootid))}">删除</a> -->
					  </if>
				  </if>
			  </td>
	        </tr>
	        </volist>
      </table>
    </div>
    <div class="fuqilai">
	    <div class="page">
			{$page}
		</div>
		<div class="numinfos" style="height: 24px; line-height: 24px; text-align: center; font-size: 15px; font-weight: bold;">总扫码次数：{$sma_num} &nbsp;&nbsp;&nbsp;&nbsp; 实际扫了 {$sell_num} 个包装</div>
	</div>
</div>
<!--查看领取奖品名单开始-->
<style type="text/css">
	.shade{position: fixed; width: 100%; height: 100%; z-index: 100; background-color: rgba(0,0,0,.6); top: 0px; left: 0px; display: none;}
	em.shade_close{display: block; position: absolute; width: 50px; height: 50px; border-radius: 100%; text-align: center; line-height: 50px; font-size: 24px; font-weight: bold; background-color: #d80917; top: 20px; right: 20px; color: #fff; cursor: pointer;}
	.shade_content{position: fixed; width: 80%; height: 80%; top: 100px; margin: 0px auto; background-color: #fff; left: 10%; border-radius: 10px; padding: 15px; overflow: auto; overflow-x: hidden;}
</style>
<div class="shade">
	<em class="shade_close">X</em>
	<div class="shade_content">
		<table width="100%" border="1" cellspacing="0" cellpadding="0" class="indextable">
			<tr class="th-bg" style="background-color: #383e4c;">
				<th width="12%">码标识</th>
				<th width="15%">码标题</th>
				<th width="10%">领取人</th>
				<th width="10%">手机号</th>
				<th width="25%">送货地址</th>
				<th width="8%">昵称</th>
				<th width="5%">性别</th>
				<th width="15%">获奖时间</th>
			</tr>
			<tbody class="awarresult"></tbody>
		</table>
	</div>
</div>
<!--查看领取奖品名单结束-->
<script type="text/javascript">
	$(function(){
		$("select.lookreuslt").change(function(){
			if($(this).val() != -1){
				var url = $(this).children('option:selected').attr('url');
			    location.href = url;
			}		    
		});

		$("a.resdel").each(function(index, element) {
			var t = $(this);
			t.click(function(){
				var r=confirm("想好！确定要删除吗？");
				if (r==true){
					var refurl = $(this).attr('refurl');
					location.href = refurl;
				}else{
					return false;
				}
			})
		});
		//查看此奖品被谁领取
		$("a.lookover").each(function(index, element) {
			var t = $(this);
			t.click(function(){
				var randcode = $(this).attr('randcode');
				var vrootid = $(this).attr('vrootid');
				var url = "{:U('lookuserinfo')}";
				var data = {"randcode":randcode,"vrootid":vrootid,random:Math.random()};
				$.ajax({
					url:url,
					data:data,
					type:"POST",
					dataType:"HTML",
					success:function (result){
						$(".shade").show();
						$("tbody.awarresult").html(result);
					}
				});
			})
		});
		//关闭
		$("em.shade_close").click(function(){
			$("tbody.awarresult").html(null);
			$(".shade").hide();
		})
//		$(".shade").click(function(){
//			$("tbody.awarresult").html(null);
//			$(".shade").hide();
//		})


	})
</script>
</body>
</html>
